/**
 * Author : wang885298.
 * Date   : 2018/7/13.
 * File   : regist-components.注册自定义组件
 */
import sideBar from './components/sidebar.vue'
import headerCommon from './components/header.vue'
/**
 * 全局注册各组件
 * @param Vue
 */
function registComponents (Vue) {
  Vue.component('sideBar', sideBar)
  Vue.component('headerCommon', headerCommon)
  Vue.directive('dragable', {
    inserted (el, binding) {
      el.style.cursor = 'move'
      el.onmousedown = (e) => {
        if (e.target.childNodes.length < 1) {
          return
        }
        var oevent = e || window.event
        var distanceX = oevent.clientX - el.offsetLeft
        var distanceY = oevent.clientY - el.offsetTop
        document.onmouseup = (e) => {
          document.onmousemove = null
          document.onmousemove = null
        }
        document.onmousemove = (e) => {
          var oevent = e || window.event
          el.style.left = oevent.clientX - distanceX + 'px'
          el.style.top = oevent.clientY - distanceY + 'px'
        }
      }
    }
  })
}
export default registComponents
